using System;
using System.IO;
using System.Reflection;
using System.Text;

using NUnit.Framework;

using octalforty.Componento.ComponentModel.Packaging;
using octalforty.Componento.SemanticModel;

namespace octalforty.Componento.Tests.ComponentModel.Packaging
{
    [TestFixture()]
    public class PackageRepositoryDefinitionParserTestFixture
    {
        [Test()]
        public void ParseRepositoryDefinition()
        {
            PackageRepositoryDefinitionParser packageRepositoryDefinitionParser = new PackageRepositoryDefinitionParser();
            RepositoryEntry[] repositoryEntries;

            using(Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("octalforty.Componento.Tests.Packages.cpd"))
            {
                using(StreamReader streamReader = new StreamReader(stream, Encoding.UTF8))
                    repositoryEntries = packageRepositoryDefinitionParser.ParseRepositoryDefinition(streamReader);
            } // using

            Assert.AreEqual(2, repositoryEntries.Length);

            Assert.AreEqual("NHibernate", repositoryEntries[0].Name);
            Assert.AreEqual(new Version(1, 2, 1, 4000), repositoryEntries[0].Version);
            Assert.AreEqual(new Uri("http://repository.componento.net/nhibernate.cpm"), repositoryEntries[0].ManifestUri);

            Assert.AreEqual("NUnit", repositoryEntries[1].Name);
            Assert.AreEqual(new Version(2, 5, 1), repositoryEntries[1].Version);
            Assert.AreEqual(new Uri("http://repository.componento.net/nunit.cpm"), repositoryEntries[1].ManifestUri);
        }
    }
}
